<template>
	<view class="container">
		<view class="eva-section" v-if=" teamList.length>0">
			<view class="e-header">
				<text class="tit">这些人刚刚购买成功，可插队拼单</text>
				<text class="yticon icon-you"></text>
			</view> 
			<view class="group-list" v-for="(item, index) in teamList" :key="index">
			<!-- <view class="group-image" v-for="(item1, index1) in item.LIST" :key="index1"> -->
			    <view class="group-image"  >
			        <image class="group-image-item" :src="item.AVATOR==null ? '/static/missing-face.png':img+item.AVATOR" mode="aspectFill"></image>
			    </view>
			    <view class="attr">{{item.NAME}}</view>
			    <view class="group-text"  @click="buy(3,item.TEAMNUM)">插队拼单</view>
			    <button class="primary" type="primary" size="mini" @click="buy(3,item.TEAMNUM)">插队拼单</button>
			 </view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				id:'',
				SIGNATURE: '',
				img:'',
				teamList:[],
				COUNTNUM:0
			}
		},
		onLoad(option) {
			this.id = option.id
			this.img = getApp().globalData.imageAddress
			this.SIGNATURE = uni.getStorageSync("SIGNATURE")
			this.COUNTNUM = option.COUNTNUM
			if (uni.getStorageSync('userInfo')) {
				this.loadTeam()
			}else{
				this.loadTeamLogin()
			}
		},
		methods: {
			//加载团队信息
			 loadTeam(){
				this.$http.post("/group/teamList",{
					SIGNATURE : this.SIGNATURE,
					ID: this.id,
					USERID: 0
				}).then((res) => {
					console.log("团中团>>>>>>>>>>>",res.data.OBJECT);
					this.teamList = res.data.OBJECT
				}).catch((err)=>{
					console.log('request fail', err);
				})
			},
			
			//加载团队信息
			 loadTeamLogin(){
				this.$http.post("/group/teamListLogin",{
					SIGNATURE : this.SIGNATURE,
					TOKEN: uni.getStorageSync('userInfo').TOKEN,
					ID: this.id,
					USERID: 0
				}).then((res) => {
					console.log("团中团>>>>>>>>>>>",res.data.OBJECT);
					if(res.data.STATE === "0" && res.statusCode === 200){
						if(res.data.OBJECT == ''){
							this.teamList.length = 0;
						}else{
							this.teamList = res.data.OBJECT
						}
					}else if(res.data.STATE != '0' && res.data.STATE != '-1' ){
						this.loadTeam()
					}
					
				}).catch((err)=>{
					console.log('request fail', err);
				})
			},
			buy(isGroup,teamNum){
				console.log(">>>>>>>>>>>>>>>>>>>>>>>>>"+isGroup,teamNum);
				if(this.COUNTNUM==0){
					uni.showModal({
						title: '提示',
						content: '该商品已抢光',
					})
				}else{
					//判断是否登录
					// let userInfo = uni.getStorageSync('userInfo') || '';
					//如果userInfo得到空值，那么未登录
					console.log("LLLLLLLLLLLLLL",uni.getStorageSync('userInfo'));
					if(uni.getStorageSync('userInfo')){
						uni.navigateTo({
							url: `/pages/order/createOrderGroup?id=`+this.id+"&num=1"+"&isGroup="+isGroup+"&teamNum="+teamNum
						})
					}else{
						// #ifdef MP-WEIXIN
						uni.showModal({
							content:'请先登录',
							success: function (res) {
							        if (res.confirm) {
							            uni.switchTab({
							            	url:"/pages/user/user"
							            })
							        } else if (res.cancel) {
							            console.log('用户点击取消');
							        }
							    }
						})
						// #endif
						// #ifndef MP-WEIXIN
						uni.navigateTo({
							url: "/pages/public/login1"
						})
						// #endif
					}
				}
				
				
			},
		}
	}
</script>

<style lang="scss">
	page, .container{
		background: $page-color-base;
		padding-bottom: 100upx;
		height: 100%;
		.swiper-Demo{
			height: 100%;
			.list-scroll-content{
				height: 100%;
			}
		}
	}
	.all{
		background-color: #f5f5f5;
		margin-top: 80upx;
	}
	/* 评价 */
	.eva-section{
		display: flex;
		flex-direction: column;
		padding: 20upx 30upx;
		background: #fff;
		margin-top: 16upx;
		.e-header{
			display: flex;
			align-items: center;
			height: 70upx;
			font-size: $font-sm + 2upx;
			color: $font-color-light;
			.tit{
				font-size: $font-base + 2upx;
				color: $font-color-dark;
				margin-right: 4upx;
			}
			.tip{
				flex: 1;
				text-align: right;
			}
			.icon-you{
				margin-left: 10upx;
			}
		}
	}
	/* 团购 */
	.group-list{
		display: flex;
		border-top: 1upx solid #EBEEF5;
		padding-top : 20upx;
		padding-buttom : 10upx;
		padding-left : 50upx;
		.group-image{
			.group-image-item{
				width: 80upx;
				height: 80upx;
				border-radius: 100%;
				margin-left: -60upx;
			}
		}
		.attr{
			position: absolute;
			left: 180upx;
			font-size: 35upx;
			margin-top: 18upx;
		}
		.group-text{
			position: absolute;
			margin-top: 20upx;
			font-size: 30upx;
			right: 57upx;
			color: #fff;
			z-index: 1;
		}
		.primary{
			
			position: absolute;
			text-align: center;
			margin-top: 10upx;
			right: 40upx;
			height: 65upx;
			width: 150upx;
			color: #FA436A;
			background-color: #FA436A;
		}
		
	}
</style>
